import { defineConfig } from '@umijs/max';

import { APP_LOGO } from '../src/appConfig';

import proxy from './proxy';
import { routes } from './routes';
import splitChunk from './splitChunk';

const path = require('path');
const { theme } = require('antd/lib');
const { convertLegacyToken } = require('@ant-design/compatible/lib');
const { defaultAlgorithm, defaultSeed } = theme;
const mapToken = defaultAlgorithm(defaultSeed);
const v4Token = convertLegacyToken(mapToken);

export default defineConfig({
  antd: {
    import: false,
    theme: {
      token: {
        colorPrimary: '#1890ff',
      },
    },
  },
  alias: {
    'lite-module-federation.config.js': path.resolve(
      process.cwd(),
      'lite-app/lite-module-federation.config.js',
    ),
    'lite-app': path.resolve(process.cwd(), 'lite-app/src'),
  },
  access: {},
  autoprefixer: { flexbox: 'no-2009' },
  analyze: {},
  clickToComponent: {
    editor: 'vscode',
  },
  cssMinifier: 'esbuild',
  cssMinifierOptions: {
    minifyWhitespace: true,
    minifySyntax: true,
  },
  devtool: 'eval',
  favicons: [APP_LOGO],
  hash: true,
  model: {},
  mountElementId: 'code',
  initialState: {},
  request: {},
  layout: {},
  lessLoader: {
    modifyVars: v4Token,
  },
  proxy: proxy['dev'],
  reactRouter5Compat: {},
  srcTranspiler: 'babel',
  mfsu: {
    strategy: 'eager',
  },
  routes,
  npmClient: 'yarn',
  dva: {},
  chainWebpack(memo) {
    splitChunk(memo);
  },
});
